/* part1test.c
 * test the syscall for the lock and condition
 */
#include "theater.h"

char * rt1scl1="rt1scl1";
char * rt1scl2="rt1scl2";
char * rt1scc1="rt1scc1";
char * rt1scc2="rt1scc2";


void SMT1()
{
    int i;
    int value;
    char * mvname1="SMT1";
    i=createMV(mvname1);
    if(i!=-1)
        Printf("rpctest 2:SMT1 create it succussfully, return %d \n",i);
    else
    {
        Printf("rpctest 2:SMT1 could not create it, return %d\n",i);
    }
    value=getMV(mvname1);
    Printf("rpctest 2:get the mv %s  the value %d \n ", mvname1,value);
    value=78;
    setMV(mvname1,value);
    Printf("rpctest 2:set the mv %s  to value %d \n ", mvname1,value);
}

void RT1SC1()
{
   CreateLock(rt1scl1);
    CreateCV(rt1scc1);
    AcquireLock(rt1scl1);
    Printf("rpctest 2:RT1SC1 is signal for the lock %s  cv %s\n",rt1scl1,rt1scc1);
    SignalCV(rt1scl1,rt1scc1);
    Printf("rpctest 2:RT1SC1 releasing up for the lock %s  cv %s\n",rt1scl1,rt1scc1);
    ReleaseLock(rt1scl1);
}

void RT1BC1()
{
    CreateLock(rt1scl2);
    CreateCV(rt1scc2);
    AcquireLock(rt1scl2);
    Printf("rpctest 2:RT1BC1 is waiting for the lock %s  cv %s\n",rt1scl2,rt1scc2);
    WaitCV(rt1scl2,rt1scc2);
    Printf("rpctest 2:RT1BC1 waked up for the lock %s  cv %s\n",rt1scl2,rt1scc2);
    ReleaseLock(rt1scl2);
}

int main()
{
    RT1LO1();
    SMT1();
    RT1SC1();
    RT1BC1();
    Exit(0);
}


